package es.goalproject.core.dao.impl;

import java.io.Serializable;
import java.util.List;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.Transactional;
import org.jboss.seam.log.Log;

import es.goalproject.core.dao.AbstractBaseDAO;
import es.goalproject.core.dao.ComunQueryService;
import es.goalproject.core.dominio.AbstractBase;

@Name("comunQueryService")
@Scope(ScopeType.SESSION)
public class ComunQueryServiceImpl implements ComunQueryService, Serializable {

	/**
	 *
	 */
	private static final long serialVersionUID = -2618669839250333092L;

	@Logger
	Log log;

	@In(create = true)
	AbstractBaseDAO abstractBaseDAO;

	@Transactional
	public void guardar(AbstractBase abstractBase) {
		if (log.isDebugEnabled()) {
			log.debug("Inicio - guardar");
		}
		abstractBaseDAO.insertOrUpdate(abstractBase);
		if (log.isDebugEnabled()) {
			log.debug("Fin - guardar");
		}
	}

	public void guardarEnEspera(AbstractBase abstractBase) {
		if (log.isDebugEnabled()) {
			log.debug("Inicio - guardar");
		}
		abstractBaseDAO.insertOrUpdate(abstractBase);
		if (log.isDebugEnabled()) {
			log.debug("Fin - guardar");
		}
	}

	@Transactional
	public void guardarLista(List<AbstractBase> lista) {
		if (log.isDebugEnabled()) {
			log.debug("Inicio - guardarLista");
		}
		abstractBaseDAO.insertOrUpdateList(lista);
		if (log.isDebugEnabled()) {
			log.debug("Fin - guardarLista");
		}
	}

	@Transactional
	public void eliminar(AbstractBase abstractBase) {
		if (log.isDebugEnabled()) {
			log.debug("Inicio - eliminar");
		}
		abstractBaseDAO.delete(abstractBase);
		if (log.isDebugEnabled()) {
			log.debug("Fin - eliminar");
		}
	}

	@Transactional
	public void eliminarLista(List<AbstractBase> lista) {
		if (log.isDebugEnabled()) {
			log.debug("Inicio - eliminarLista");
		}
		abstractBaseDAO.deleteList(lista);
		if (log.isDebugEnabled()) {
			log.debug("Fin - eliminarLista");
		}
	}

}
